home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / SAT 2.3.8 / Demos / SATminimal demo ƒ / sMySprite.c < prev    next >
C/C++ Source or Header  |  1995-12-17  |  1KB  |  49 lines

  1. #include "SAT.h"
  2.  
  3.     Handle    theSound;
  4.     FacePtr    faces[6];
  5.  
  6. /* Prototypes */
  7.  void InitMySprite();
  8.  pascal void SetupMySprite (SpritePtr me);
  9.  pascal void HandleMySprite (SpritePtr me);
  10.  
  11.  
  12. void InitMySprite()
  13. {
  14. int i;
  15.  
  16.     theSound = SATGetSound(128);    /*Preload the sound */
  17.     for (i=0; i<=5; i++)
  18.         faces[i] = SATGetFace(128+i);    /* Preload all sprite faces */
  19. }
  20.  
  21. /* Important! Callback routines (Setup, Handle, Hit) must be declared "pascal"! */
  22.  
  23. pascal void SetupMySprite (SpritePtr me)
  24. {
  25.     me->mode = 0;                    /* Pick a valid face number */
  26.     me->speed.h = 2;                /* Set the speed - only horizontal is used here */
  27.     me->task = HandleMySprite;        /* Set a handling routine. MANDATORY! If nil, the sprite will self-destruct. */
  28. }
  29.  
  30. pascal void HandleMySprite (SpritePtr me)
  31. {
  32. /* Choose face */
  33.     me->mode = (me->mode + 1) % 6;
  34.     me->face = faces[me->mode];
  35.  
  36. /* Move */
  37.     me->position.h = me->position.h + me->speed.h;
  38.     if (me->position.h > gSAT.offSizeH - 16)
  39.         {
  40.             me->speed.h = -2;
  41.             SATSoundPlay(theSound, 1, false);
  42.         };
  43.     if (me->position.h < -16)
  44.         {
  45.             me->speed.h = 2;
  46.             SATSoundPlay(theSound, 1, false);
  47.         };
  48. }
  49.